package com.wen.controller;

import com.wen.bean.UserInfoBean;
import com.wen.model.UserModel;
import com.wen.uilts.MyUilts;
import org.apache.commons.lang3.StringUtils;

import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;
import java.io.IOException;
import java.util.List;

@WebServlet(name = "UserInfoQueryServlet", value = "/UserInfoQueryServlet")
public class UserInfoQueryServlet extends HttpServlet {
    @Override
    protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    //获取表单数据并把表单数据保存在实例中
        UserInfoBean userInfoBean = MyUilts.getNewInstance(UserInfoBean.class);
        userInfoBean.setUserName(request.getParameter("userName"));
        userInfoBean.setPhone(request.getParameter("phone"));
        System.out.println(request.getParameter("userDate"));
        if (StringUtils.isNotEmpty(request.getParameter("userDate"))){
        userInfoBean.setUserDate(MyUilts.strConvertDate(request.getParameter("userDate"),"yyyy-MM-dd HH:mm:ss"));
        }
        if (StringUtils.isNotEmpty(request.getParameter("userDate2"))){
        userInfoBean.setUserDate2(MyUilts.strConvertDate(request.getParameter("userDate2"),"yyyy-MM-dd HH:mm:ss"));
        }
        //调用model层进行数据保存的业务逻辑处理
        List<UserInfoBean> lstUsers = MyUilts.getNewInstance(UserModel.class).queryUserInfoByParams(userInfoBean);

        // 调用Model层进行查询操作，将用户数据查询出来，保存到session中
        // 在跳转之前，需要将显示在成功页面的数据进行session缓存
        request.getSession().setAttribute("lstUser", lstUsers);

        // 3 显示查询结果页面
        request.getRequestDispatcher("WEB-INF/viewPages/userInfoB/UserInfoAddDetail.jsp").forward(request, response);
    }

}
